博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Web功能之组织结构图
阅读量:6363 次
发布时间:2019-06-23

本文共 8184 字,大约阅读时间需要 27 分钟。

    前提:由于项目需要显示组织结构图的形式 

    工具:VS2010 

    项目:ASP.NET 自带的web项目 (带模板页)

    插件:OrgChart(依赖:OrgChart.dll)、JOrgChart

    不多说 先看效果

    1、OrgChart实现效果

    

 

    2、JOrgChart效果

    

    基础实体类代码:

public class SysUserModel : OrgNode    {        public int SysUserId { get; set; }        public string SysUserName { get; set; }        public int SysUserParentId { get; set; }        public override string OrgNodeHtml()        {            this.SysUserName = this.Text;            string str = "
"; //str += "
"; str += "
"; //str += "
"; str += "
";//" + this.SysUserGroupId + " str += "
"; // str += "
"; //str += "
"; str += "
 " + this.SysUserGroupId + "
 
 " + this.SysUserName + "
 
 
"; str += "
"; return str; } }
View Code

    1、OrgChart前台实现代码: 

<%@ Page Title="OrgChart" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"    CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %><%@ Register Assembly="OrgChart" Namespace="OrgCharDesigner" TagPrefix="cc1" %>
View Code

        OrgChart后台实现代码:

SysUserModel sysUserModel = new SysUserModel();        DataTable dt;        protected void Page_Load(object sender, EventArgs e)        {            if (!IsPostBack)            {                ListBind();            }        }               protected void ListBind()        {            try            {                dt = dtList();                SysUserModel root = new SysUserModel();                root.SysUserId = 1;                root.Text = "CEO";                root.SysUserParentId = 0;                SetNodeChild(dt, root);                OrgChart1.Node = root;            }            catch (Exception ex)            {                throw ex;            }        }        private void SetNodeChild(DataTable dt, SysUserModel root)        {            DataRow[] rows = dt.Select(" SysUserParentId = '" + root.SysUserId + "'");// 选出所有子节点            foreach (DataRow drChild in rows)            {                SysUserModel node = new SysUserModel();                node.Text = drChild["SysUserName"].ToString();                node.SysUserId = int.Parse(drChild["SysUserId"].ToString());                node.SysUserParentId = int.Parse(drChild["SysUserParentId"].ToString());                SetNodeChild(dt, node);                root.Nodes.Add(node);            }        }        private DataTable dtList()        {            DataTable dt = new DataTable();            dt.Columns.Add("SysUserId");            dt.Columns.Add("SysUserName");            dt.Columns.Add("SysUserParentId");            dt.Rows.Add();            dt.Rows[0]["SysUserId"] = "1";            dt.Rows[0]["SysUserName"] = "CEO";            dt.Rows[0]["SysUserParentId"] = "0";            dt.Rows.Add();            dt.Rows[1]["SysUserId"] = "2";            dt.Rows[1]["SysUserName"] = "总经理";            dt.Rows[1]["SysUserParentId"] = "1";            dt.Rows.Add();            dt.Rows[2]["SysUserId"] = "3";            dt.Rows[2]["SysUserName"] = "副总经理";            dt.Rows[2]["SysUserParentId"] = "2";            dt.Rows.Add();            dt.Rows[3]["SysUserId"] = "4";            dt.Rows[3]["SysUserName"] = "项目一组";            dt.Rows[3]["SysUserParentId"] = "3";            dt.Rows.Add();            dt.Rows[4]["SysUserId"] = "5";            dt.Rows[4]["SysUserName"] = "项目二组";            dt.Rows[4]["SysUserParentId"] = "3";            dt.Rows.Add();            dt.Rows[5]["SysUserId"] = "6";            dt.Rows[5]["SysUserName"] = "运营总经理";            dt.Rows[5]["SysUserParentId"] = "1";            dt.Rows.Add();            dt.Rows[6]["SysUserId"] = "7";            dt.Rows[6]["SysUserName"] = "运营副总经理";            dt.Rows[6]["SysUserParentId"] = "6";            dt.Rows.Add();            dt.Rows[7]["SysUserId"] = "8";            dt.Rows[7]["SysUserName"] = "运营一组";            dt.Rows[7]["SysUserParentId"] = "7";            dt.Rows.Add();            dt.Rows[8]["SysUserId"] = "9";            dt.Rows[8]["SysUserName"] = "运营二组";            dt.Rows[8]["SysUserParentId"] = "7";            return dt;        }
View Code

    2、JOrgChart 前台实现代码:

<%@ Page Title="jOrgChart" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"    CodeBehind="About.aspx.cs" Inherits="WebApplication1.About" %>    
<%=html%>
View Code

         JOrgChart 后台实现代码:

StringBuilder str = new StringBuilder();        DataTable dt;        protected string html;        protected void Page_Load(object sender, EventArgs e)        {            if (!IsPostBack)            {                html = ListBind();            }        }        protected string ListBind()        {            try            {                dt = dtList();                SysUserModel root = new SysUserModel();                str.Append(" 
  • CEO "); root.SysUserId = 1; root.Text = "CEO"; root.SysUserParentId = 0; SetNodeChild(dt, root); str.AppendLine("
"); return str.ToString(); } catch (Exception ex) { throw ex; } } private void SetNodeChild(DataTable dt, SysUserModel root) { DataRow[] rows = dt.Select(" SysUserParentId = '" + root.SysUserId + "'");// 选出所有子节点 if (rows.Length > 0) { str.Append("
    "); foreach (DataRow drChild in rows) { str.AppendFormat("
  • {1}", drChild["SysUserId"].ToString(), drChild["SysUserName"].ToString()); SysUserModel node = new SysUserModel(); node.Text = drChild["SysUserName"].ToString(); node.SysUserId = int.Parse(drChild["SysUserId"].ToString()); node.SysUserParentId = int.Parse(drChild["SysUserParentId"].ToString()); SetNodeChild(dt, node); str.Append("
  • "); } str.Append("
"); } } private DataTable dtList() { DataTable dt = new DataTable(); dt.Columns.Add("SysUserId"); dt.Columns.Add("SysUserName"); dt.Columns.Add("SysUserParentId"); dt.Rows.Add(); dt.Rows[0]["SysUserId"] = "1"; dt.Rows[0]["SysUserName"] = "CEO"; dt.Rows[0]["SysUserParentId"] = "0"; dt.Rows.Add(); dt.Rows[1]["SysUserId"] = "2"; dt.Rows[1]["SysUserName"] = "总经理"; dt.Rows[1]["SysUserParentId"] = "1"; dt.Rows.Add(); dt.Rows[2]["SysUserId"] = "3"; dt.Rows[2]["SysUserName"] = "副总经理"; dt.Rows[2]["SysUserParentId"] = "2"; dt.Rows.Add(); dt.Rows[3]["SysUserId"] = "4"; dt.Rows[3]["SysUserName"] = "项目一组"; dt.Rows[3]["SysUserParentId"] = "3"; dt.Rows.Add(); dt.Rows[4]["SysUserId"] = "5"; dt.Rows[4]["SysUserName"] = "项目二组"; dt.Rows[4]["SysUserParentId"] = "3"; dt.Rows.Add(); dt.Rows[5]["SysUserId"] = "6"; dt.Rows[5]["SysUserName"] = "运营总经理"; dt.Rows[5]["SysUserParentId"] = "1"; dt.Rows.Add(); dt.Rows[6]["SysUserId"] = "7"; dt.Rows[6]["SysUserName"] = "运营副总经理"; dt.Rows[6]["SysUserParentId"] = "6"; dt.Rows.Add(); dt.Rows[7]["SysUserId"] = "8"; dt.Rows[7]["SysUserName"] = "运营一组"; dt.Rows[7]["SysUserParentId"] = "7"; dt.Rows.Add(); dt.Rows[8]["SysUserId"] = "9"; dt.Rows[8]["SysUserName"] = "运营二组"; dt.Rows[8]["SysUserParentId"] = "7"; return dt; }
View Code

 

以上是本人对于组织结构图的总结 如有好的建议 请您留下  以便新手学习 利人利自!

项目下载地址:

 

转载于:https://www.cnblogs.com/yhyjy/p/3889858.html

你可能感兴趣的文章
iOS开发小技巧--利用MJExtension解决数据结构复杂的模型转换
查看>>
Python中的图形库
查看>>
Linux操作系统分析 ------------------中国科技大学
查看>>
Apache多站点实现原理和配置
查看>>
javascript类型系统——包装对象
查看>>
Android4.4中不能发送SD卡就绪广播
查看>>
解决:sudo: 无法解析主机:dinphy-500-310cn: 连接超时
查看>>
Asp.Net多线程用法1
查看>>
exFAT是支持Mac和Win的
查看>>
(转)postman中 form-data、x-www-form-urlencoded、raw、binary的区别
查看>>
js Date操作
查看>>
判断用户密码是否在警告期内(学习练习)
查看>>
sp_executesql的执行计划会被重用(转载)
查看>>
禅道项目管理软件插件开发
查看>>
Linux系统各发行版镜像下载
查看>>
JS获取键盘按下的键值event.keyCode,event.charCode,event.which的兼容性
查看>>
查看ORACLE 数据库及表信息
查看>>
腾讯、百度、阿里面试经验—(1) 腾讯面经
查看>>
Codeforces Round #374 (Div. 2) D. Maxim and Array 贪心
查看>>
HTML DOM 教程Part1
查看>>